//
//  C_RedioCollectionViewCell.m
//  音悦咖
//
//  Created by Best on 15/7/15.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "C_RedioCollectionViewCell.h"
#import "BaseHeader.h"

@implementation C_RedioCollectionViewCell

- (void)dealloc
{
    
    [_imageView release];
    [super dealloc];
}


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self create];
    }
    return self;
}


- (void)create
{
    self.imageView = [[UIImageView alloc] init];
    [self addSubview:self.imageView];
    [_imageView release];
    
    self.titleLabel = [[UILabel alloc] init];
    [self.imageView addSubview:self.titleLabel];
    self.titleLabel.textColor = [UIColor whiteColor];
    [_titleLabel release];
    
    self.countLabel = [[UILabel alloc] init];
    [self.imageView addSubview:self.countLabel];
    self.countLabel.font = [UIFont systemFontOfSize:13];
    self.countLabel.textColor = [UIColor whiteColor];

    [_countLabel release];
    
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
       self.imageView.frame = layoutAttributes.bounds;
    CGFloat width = self.imageView.frame.size.width;
    CGFloat height = self.imageView.frame.size.height;

    self.titleLabel.frame = CGRectInset(self.imageView.bounds, width / 2 - 20, height / 2 - 10);
    [self.titleLabel sizeToFit];
    self.countLabel.frame = CGRectMake(self.titleLabel.frame.origin.x, self.titleLabel.frame.size.height + self.titleLabel.frame.origin.y, self.titleLabel.frame.size.width, self.titleLabel.frame.size.height);
    [self.countLabel sizeToFit];
    
    
}


- (void)setImageModel:(C_RedioImageModel *)imageModel
{
    if (_imageModel != imageModel) {
        [_imageModel release];
        _imageModel = [imageModel retain];
    }
    
    [self.imageView setImageWithURL:imageModel.pic_url_240_200 placeholderImage:[UIImage imageNamed:@"place.jpg"]];
    self.titleLabel.text = imageModel.tag_name;
    self.countLabel.text = [[imageModel.quantity description] stringByAppendingString:@"首"];
    NSLog(@"%@", self.countLabel.text);

}

@end
